home *** CD-ROM | disk | FTP | other *** search
- VI. EXTENDED MEMORY
-
-
-
- 1. MEMORY MAP OF F-PC
-
-
-
- F-PC was built to handle a class of programming problems that
- require very large memory and cannot be handled well on any normal
- 64K implementation of Forth because of space constraints.
-
- The memory map of F-PC can be shown schematically as follows:
-
-
- |---------------------| ?CS:
- ^ | |
- | | Forth |
- | | Kernel |
- | | |
- | |---------------------|
- | | System |
- | | Extensions |
- | |---------------------| HERE, DP @
- | | Dictionary | PAD, DP + 80
- | | Free space |
- 64k | | |
- bytes | v |
- | | ^ |
- | | | |
- | | Data stack |
- | |---------------------| SP0 @
- | | TIB | TIB, 'TIB @
- | | | |
- | | v |
- | | ^ |
- | | | |
- v | Return stack |
- |---------------------| RP0 @, End code space.
-
- |---------------------| YSEG @, Start head space.
- ^ | hash table |
- | |---------------------|
- | | |
- 64k | headers |
- bytes | |
- | |---------------------| YHERE, YDP @
- | | header |
- v | free space | YHERE + 65535
- |---------------------|
-
- |---------------------| TSEGB, TSEGE
- ^ | |
- 64k bytes | Edit Buffer |
- | | |
- | |---------------------| LSEG
- | | Line pointer list |
- | |---------------------| DSEG
- | | Lines deleted buf |
- | |---------------------| RSEG
- v | Restore display buf |
- |---------------------|
-
- |---------------------| XSEG @, Start list space.
- ^ | |
- | | List of |
- | | |
- 64k | Colon Definitions |
- bytes | |
- or | and Strings |
- more | |
- | |---------------------| XHERE, XDP @
- | | |
- | | header |
- | | free space |
- v | |
- |---------------------|
-
-
-
-
- F-PC allows the list (colon space) segment to be much larger than
- 64K bytes. Strings have also been moved out of code space back
- into LIST space, which means there is effectively unlimited space
- for text messages. In fact the only real limitation in size comes
- from the fact that there are only 64k available for heads.
- Calculations indicate there is room for about 3300 definitions on
- top of the current system of about 2000 words. This calculation
- is based on an average name length of 5 characters, with an
- average header length of 12 bytes. With 5300 total definitions,
- less than 30k of code space would be used for code fields of colon
- definitions, leaving the remaining 30+k of code space for
- variables and arrays. Not an infinitely large application
- obviously but probably large enough for most (99%) applications.
-
- F-PC places a segment (ES) and and offset (IP) on the return stack
- for each nest operation. Only the starting relative segment is
- compiled into the code field, and the conversion to absolute
- segment is performed by NEST. This makes the code fully
- relocatable as is required by the DOS environment. Some
- performance could be gained by using absolute segment addressing,
- and performing a conversion at save and load time to and from
- relative and absolute, but I have not done this, and don't plan to
- for now. The performance gain would come from having a simpler
- NEST, what would not need to perform the relative to absolute
- conversion at runtime. This system looses about 20% in
- nest/unnest performance due exclusively to that conversion.
-
- CS and DS always point to the code space, and so all assembly
- language operations work with data in the code segment unless a
- special operator like @L or !L is used to reach an external memory
- area. This means there is no penalty to be paid for most Forth
- operations.
-
- Here is the data structure used for a colon definition in F-PC:
-
-
-
- ----------------
- HEAD SPACE [ VIEW offset ] VIEW
- [ LINK pointer ] LINK
- [ 83 hex ] NAME
- [ H ]
- [ E ]
- [ X + 80 hex ]
- Points to CODE space [ CFA pointer ] --------v
- ---------------- |
- |
- ---------------- |
- CODE SPACE [ CALL ] CFA <---<
- [ NEST ]
- Points to LIST space [ LIST POINTER ] BODY >--v
- ---------------- |
- |
- ---------------- |
- LIST SPACE [ cfa of (LIT) ] LIST <--<
- [ 16 ]
- [ cfa of BASE ]
- [ cfa of ! ]
- [ cfa of UNNEST]
- ----------------
-
-
- 2. EXTENDED MEMORY WORD SET
-
-
-
- A complete set of words are defined in F-PC to let the user
- accessing the extended memory very conveniently. The standard
- Forth memory accessing words are retained for addressing the
- code/data segment in the memory. Generic extended memory words
- are appended with the letter L, and they require address
- specifications in segment/offset pairs. Words addressing the list
- space have X prefix and words addressing the head space have Y
- prefix.
-
- Generic Extended Memory Words are those which require explicit
- segment information with the 16 bit address offset. They are the
- basic word set from which other segment specific memory words are
- derived. This word set includes the following words:
-
- @L ( seg addr -- n ) Fetch 16 bit integer.
-
- !L ( n seg addr -- ) Store 16 bit integer.
-
- C@L ( seg addr -- b ) Fetch a byte.
-
- C!L ( b seg addr -- ) Store a byte.
-
- CMOVEL ( seg addr seg' addr' n -- )
- Move n bytes from seg-addr to
- seg'-addr'.
-
- CMOVEL> ( seg addr seg' addr' n -- )
- Move n bytes in revered order.
-
- LFILL ( seg addr n b -- ) Fill n bytes at seg-addr
- with b.
-
- LDUMP ( addr n -- ) Dump n byte from segment pointed
- to by DUMPSEG with addr offset.
-
-
- Following are words addressing the list space:
-
-
- X@ ( addr -- n ) Fetch an integer in list space
-
- X! ( n addr -- ) Store integer to list space
-
- XC@ ( addr -- b ) Fetch byte.
-
- XC! ( b addr -- ) Store byte.
-
- X, ( n -- ) Compile integer to top of
- the list dictionary.
-
- XC, ( b -- ) Compile byte to the list
- dictionary.
-
- XDUMP ( addr n -- ) Dump n bytes in the list
- segment.
-
- ?XS: ( -- seg ) Return the base of the list
- segment.
-
- XDP ( -- addr ) Pointer to top of list
- dictionary.
-
- XHERE ( -- addr ) Address of top of list
- dictionary.
-
- XPERFORM ( addr -- ) Execute word at addr.
-
-
-
- The corresponding words addressing into the head space are:
-
-
- Y@ ( addr -- n ) Fetch integer from head space.
-
- Y! ( n addr -- ) Store integer to head space.
-
- YC@ ( addr -- b ) Fetch byte.
-
- YC! ( b addr -- ) Store byte.
-
- Y, ( n -- ) Compile integer to head
- dictionary.
-
- YCSET ( b addr -- ) Set bits in a byte.
-
- YDUMP ( addr n -- ) Dump n bytes from addr in the
- head space.
-
- YDP ( -- addr ) Pointer to top of head
- dictionary.
-
- YHERE ( -- addr ) Address of top of head
- dictionary.
-
-
-
- 3. MEMORY ALLOCATION
-
-
-
- Finally, two very important words which allows you to allocate and
- deallocate extended memory by asking the DOS for unused free
- memory:
-
-
- ALLOC ( n1 -- n2 seg flag ) Request n bytes of free memory
- from DOS. Flag=0 if ok, 8 if
- not enough memory. Seg is the
- segment base of the allocated
- memory. n2 byte actually
- allocated.
-
- DEALLOC ( seg -- flag ) Release a block of memory to
- DOS. Seg should be the same
- as obtained from ALLOC.
- Flag=0 if ok, 9 if seg is not
- valid.
-